/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import DAO.DAO;
import GUI.FrameControlDanhMuc.JIFKhachHang;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Endlesslove
 */
public class BaoCaoTon implements IDaTa
{
    
    public ResultSet ThongKeTon(int thang, int nam,String maBCTruoc){
         try
        {
            List<String> params = new ArrayList<>();
            params.add("smallint:" + thang) ;//makhachhang
            params.add("int:" +  nam);//tenkhachhang
             params.add("char:" +  maBCTruoc);//tenkhachhang
            return DAO.CallProc("BCT", params);
        } 
        catch (Exception ex) 
        {
            Logger.getLogger(JIFKhachHang.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
     public ResultSet LayThangBCT(String maBC){
         try
        {
            List<String> params = new ArrayList<>();
            params.add("char:" + maBC) ;//makhachhang
           return DAO.CallProc("LayThangBaoCaoTon", params);
        } 
        catch (Exception ex) 
        {
            Logger.getLogger(JIFKhachHang.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
     public ResultSet LayMaBCTTheoThangNam(int thang, int nam){
         try
        {
            List<String> params = new ArrayList<>();
            params.add("tinyint:" + thang) ;
            params.add("smallint:" + nam) ;
           return DAO.CallProc("LayMaBaoCaoTonTheoThangNam", params);
        } 
        catch (Exception ex) 
        {
            Logger.getLogger(JIFKhachHang.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
    @Override
    public ResultSet Search(DTO.Idata Obj)
    {
//        try
//            {
//                List<String> params = new ArrayList<>();
//                params.add("char:" +  param[0]) ;//masach
//                return DAO.CallProc("LayThongTinHoaDon", params);
//
//            } 
//            catch (Exception ex) 
//            {
//                return null;
//            }
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean Update(DTO.Idata Obj)
    {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean Delete(DTO.Idata Obj)
    {
        List<String> params = new ArrayList<>();
        params.add("char:" + ((DTO.BaoCaoTon)Obj).getID());
        return DAO.CallProc("XoaBaoCaoTon", params, true);
    }

    @Override
    public void LoadData(Object table) 
    {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean Insert(DTO.Idata Obj) 
    {
        List<String> params = new ArrayList<>();
        params.add("char:" +  ((DTO.BaoCaoTon)Obj).getID()) ;//ma 
        params.add("smallint:" +  ((DTO.BaoCaoTon)Obj).ThangBaoCao);//Thang
         params.add("smallint:" +  ((DTO.BaoCaoTon)Obj).NamBaoCao);//Thang
        return DAO.CallProc("ThemBaoCaoTon", params, true);
    }

    @Override
    public String GenerateID() 
    {
        try 
        {
            ResultSet res = DAO.CallProc("LayMaBaoCaoTonCuoi");
            if (res.next())
            {    
              int index  = Integer.parseInt(((String)res.getObject(1)).split("BCT")[1].trim());
              String ms = "BCT";
              ms += (index+1)>=10?(index+1)>=100? (index +1) : "0" + (index +1) : "00" + (index + 1);
              return ms;
            }
            return "BCT001";
        } 
        catch (SQLException ex) 
        {
            return "BCT001";
        }
        catch(Exception ie)
        {
             return "BCT001";
        }
    }
    
}
